# Step 1: Build React App
FROM node:16 AS build

# 设置工作目录
WORKDIR /app

# 复制 package.json 和 package-lock.json
COPY package*.json ./

# 使用 --legacy-peer-deps 解决依赖冲突
RUN npm install --legacy-peer-deps

# 复制整个项目文件
COPY . .

# 构建 React 项目
RUN npm run build

# Step 2: Setup Nginx to serve the build
FROM nginx:alpine

# 复制 React build 文件到 Nginx 默认目录
COPY --from=build /app/build /usr/share/nginx/html

# 复制自定义的 Nginx 配置文件
COPY default.conf /etc/nginx/conf.d/default.conf

# 暴露端口 80
EXPOSE 80
